#!/bin/sh

>tmp$$
>tmp1$$
for stock in `./competitors.sh $1`
do
  curl -stderr "http://finance.yahoo.com/q/ks?s=$stock" >> tmp$$
  export title="$title  $stock"
  export price=`./quote.sh $stock |cut -d':' -f2 |awk '{print $1}'`
  export prices="$prices  $price"
done

echo $title  |sed 's/ /\t/g' >  tmp1$$
echo $prices |sed 's/ /\t/g' >> tmp1$$
echo "-------------------------------" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Market Cap" -A 2 |egrep -o ">[0-9]+.[0-9]+[M|B]<|N/A" |sed -e 's/>//g' -e 's/<//g'|tr '\n' '\t' >> tmp1$$
#cat  tmp  |sed 's/\<td/\n/g' |grep "Enterprise Value" -A 2 |egrep -o ">[0-9]+.[0-9]+[M|B]<|N/A" |sed -e 's/>//g' -e 's/<//g'|tr '\n' '\t' >> tmp1$$
echo "|Cap" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Forward P/E" -A 3 |egrep -o ">[0-9]+.[0-9]+|N/A" |sed -e 's/>//g' |tr '\n' '\t'     >> tmp1$$
echo "|PE" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "PEG Ratio" -A 2 |egrep -o ">[0-9]+.[0-9]+|N/A" |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|PEG" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Price\/Sales" -A 2 |egrep -o ">[0-9]+.[0-9]+|N/A"  |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|Price/Sales" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Price\/Book" -A 2 |egrep -o ">[0-9]+.[0-9]+|N/A"  |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|Price/Book" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Return on Assets" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A"|sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|ROA" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Return on Equity" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A"  |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|ROE" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Diluted EPS" -A 2 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A"  |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|EPS" >> tmp1$$

#cat  tmp  |sed 's/\<td/\n/g' |grep "Book Value Per Share" -A 2 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A"  |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
#echo "|Book/Share" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Beta" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A"  |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|Beta" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Insiders" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+%|N/A" |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|Insiders%" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Short % of Float" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+%|N/A" |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|Short Interest%" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Debt/Equity" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A" |sed -e 's/>//g' |tr '\n' '\t' >> tmp1$$
echo "|Debt/Share" >> tmp1$$

cat  tmp$$  |sed 's/\<td/\n/g' |grep "Book Value Per Share" -A 3 |egrep -o "[>|>-][0-9]+.[0-9]+|N/A" |sed -e 's/>//g' |awk '{printf("%4.2f\n",$1)}' |tr '\n' '\t'  >> tmp1$$
echo "|BookValue/Share" >> tmp1$$

echo "-------------------------------" >> tmp1$$
cat tmp1$$  

